package com.soar.framework.app;

import android.app.Application;

import com.soar.framework.net.http.OkHttpUtils;
import com.soar.framework.net.http.https.HttpsUtils;
import com.soar.framework.net.http.log.LoggerInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

public class FrameworkApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
    }

    /**
     * 初始化 OkHttp
     * @param timeoutConnect
     * @param timeoutRead
     * @param timeoutWrite
     */
    protected void initOkHttp(int timeoutConnect, int timeoutRead, int timeoutWrite) {
        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .connectTimeout(timeoutConnect, TimeUnit.MILLISECONDS)
                .readTimeout(timeoutRead, TimeUnit.MILLISECONDS)
                .writeTimeout(timeoutWrite, TimeUnit.MILLISECONDS)
                .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager);
        if (FrameworkConstants.DEBUG) {
            builder.addInterceptor(new LoggerInterceptor("XIAOZE-TAG"));
        }
        OkHttpClient okHttpClient = builder.build();
        OkHttpUtils.initClient(okHttpClient);
    }
}
